﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Deixei;

using Deixei.Domain.Service;
using Microsoft.Practices.Unity;

namespace Deixei.Web
{
    public class DeixeiViewPage<TModel> : ViewPage<TModel>
    {

        protected virtual void CheckBrowserVersion()
        {

            HttpBrowserCapabilitiesBase browser = base.ViewContext.HttpContext.Request.Browser;
            string Browser = browser.Browser;
            //// browser.MajorVersion
            //// browser.MinorVersion, 
            string UserAgent = base.ViewContext.HttpContext.Request.UserAgent;
            // TODO: Check Browser Version
            if (UserAgent == string.Empty)
            {
                throw new Exception();
            }
        }


        public override void InitHelpers()
        {
            this.CheckBrowserVersion();
            base.InitHelpers();
        }

        public DeixeiWebContext DeixeiWebContext
        {
            get
            {
                return base.ViewContext.DeixeiWebContext();
            }
        }

        private ApplicationContext _appContext = null;

        public ApplicationContext ApplicationContext
        {
            get
            {
                if ( _appContext == null )
                {
                    _appContext = new ApplicationContext();
                }
                return _appContext;
            }
            set
            {
                _appContext = value;
            }
        }

    }

    public class DeixeiViewPage : DeixeiViewPage<object>
    {

    }
}
